package com.chisheng.caa.controller;

import com.chisheng.caa.pojo.response.JsonResponse;
import com.chisheng.caa.pojo.dto.LoginUserDTO;
import com.chisheng.caa.pojo.dto.UserInfoDTO;
import com.chisheng.caa.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Api("用户服务接口")
@RestController
@RequestMapping(value = "/api/caa/user", produces = MediaType.APPLICATION_JSON_VALUE)
public class UserController {

    @Resource
    private UserService userService;

    @ApiOperation("登录")
    @PostMapping("/login")
    public JsonResponse<String> login(@ApiParam("登录用户信息") @RequestBody LoginUserDTO loginUser) {
        return JsonResponse.success(userService.login(loginUser));
    }

    @ApiOperation("获取用户信息")
    @GetMapping("/info")
    public JsonResponse<UserInfoDTO> info() {
        return JsonResponse.success(userService.getUserInfo());
    }

    @ApiOperation("退出登录")
    @PostMapping("/logout")
    public JsonResponse<Boolean> logout() {
        return JsonResponse.success(userService.logout());
    }

}
